package xhwl.insurance.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.ArrayList;

import xhwl.android.common.util.StringUtil;
import xhwl.insurance.R;
import xhwl.insurance.http.bean.resp.ProcessListResp;

/**
 * Created by admin on 2017/7/31.
 */

public class AllCardDealAdapter extends BaseAdapter {

    Context context;
    ArrayList<ProcessListResp> list;

    public AllCardDealAdapter(Context context, ArrayList<ProcessListResp> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if(convertView == null){
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.all_deal_item,null);
            holder.title = (TextView) convertView.findViewById(R.id.item_title);
            holder.name = (TextView) convertView.findViewById(R.id.item_name);
            holder.status = (TextView) convertView.findViewById(R.id.item_status);
            holder.time = (TextView) convertView.findViewById(R.id.item_time);
            holder.iv_order_status=(ImageView)convertView.findViewById(R.id.iv_order_status);
            holder.hmo_card_iv=(ImageView)convertView.findViewById(R.id.hmo_card_iv);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }
        holder.title.setTextColor(context.getResources().getColor(R.color.text_color_33));
        holder.name.setTextColor(context.getResources().getColor(R.color.text_color_66));
        holder.time.setTextColor(context.getResources().getColor(R.color.text_color_66));

        holder.title.setText(voildEmptyData(list.get(position).getSALE_NAME()));
        holder.name.setText("会员姓名："+voildEmptyData(list.get(position).getPERSON_NAME()));
        if("处理中".equals(list.get(position).getORDER_STATUS())){
            holder.status.setTextColor(context.getResources().getColor(R.color.orange));
            holder.iv_order_status.setImageResource(R.drawable.processing_oredr);
        }else if("成功".equals(list.get(position).getORDER_STATUS())){
            holder.status.setTextColor(context.getResources().getColor(R.color.green));
           holder.iv_order_status.setImageResource(R.drawable.success_order);
        }else if("无效".equals(list.get(position).getORDER_STATUS())){
            holder.status.setTextColor(context.getResources().getColor(R.color.hintgray));
            holder.iv_order_status.setImageResource(R.drawable.invalid_order);
        }else if("提交失败".equals(list.get(position).getORDER_STATUS())){
            holder.status.setTextColor(context.getResources().getColor(R.color.red));
            holder.title.setTextColor(context.getResources().getColor(R.color.red));
            holder.name.setTextColor(context.getResources().getColor(R.color.red));
            holder.time.setTextColor(context.getResources().getColor(R.color.red));
            holder.iv_order_status.setImageResource(R.drawable.fail_order);
        }
        holder.status.setText(voildEmptyData(list.get(position).getORDER_STATUS()));
        holder.time.setText("时间："+voildEmptyData(list.get(position).getCREATE_DATE()));
        Glide.with(context).load(list.get(position).getCARD_PIC()).error(R.drawable.icon_fail).into( holder.hmo_card_iv);
        return convertView;
    }

    class ViewHolder{
        TextView title,name,status,time;
       ImageView iv_order_status,hmo_card_iv;
    }

    public String voildEmptyData(String str) {
        if (StringUtil.isEmpty(str)) {
            return "未知";
        } else
            return str;
    }
}
